package com.example.myapplication.enity;


import android.content.Context;


import com.example.myapplication.R;
import android.content.res.Resources;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Objects;


public class IconInfo {
    public int id;
    public String name;
    public String path;
    public int pic;

    public static ArrayList<IconInfo> getDefaultList(Context context) throws IllegalAccessException {
        ArrayList<IconInfo> IconsList = new ArrayList<IconInfo>();
        //获取drawable文件名列表，不包含扩展名
        Field[] fields = R.drawable.class.getDeclaredFields();
        Resources resources = context.getResources();

        for (Field field : fields) {
            int resourceId = field.getInt(field); // 获取资源ID
            String resourceName = resources.getResourceEntryName(resourceId); // 获取资源名称
            if(!Objects.equals(resourceName, "ic_launcher_background") && !Objects.equals(resourceName, "ic_launcher_foreground")){
                IconInfo iconInfo = new IconInfo();
                iconInfo.name = resourceName;
                iconInfo.pic = resourceId;
                IconsList.add(iconInfo);
            }
        }

        return IconsList;
    }
    }